<?php
/**
 * The template for displaying all pages.
 *
 * This is the template that displays all pages by default.
 * Please note that this is the WordPress construct of pages
 * and that other 'pages' on your WordPress site will use a
 * different template.
 *
 * @package WordPress
 * @subpackage Twenty_Twelve
 * @since Twenty Twelve 1.0
 */

global $post;
get_header(); 

// $arrGoodsInfo = new stdclass();
$arrGoodsInfo = new stdClass();
if(isset($_POST['add_to_cart'])){ 
	$arrGoodsInfo->goods_id = $_POST["goods_id"];
	$arrGoodsInfo->qty = 1;
	
// var_dump($arrGoodsInfo);
// var_dump($_POST["post_id"]);
// return;
    $result = add_to_order_cart($arrGoodsInfo);
    wp_redirect(get_permalink(get_page_id("order-cart")));
}

//var_dump($_SESSION["order_cart"]);

?>
    <div class="row-fluid">
        <div id="primary" class="site-content span12">   
            <?php woo_main_before();?>
    		<div id="content" role="main">
                
			<table class="table table-hover order-cart">
				<thead>
					<tr>
						<th style="width: 100px;">Hình</th>
						<th>Tên sản phẩm</th>
						<th>Giá bán (1 SP)</th>
						<th>Số lượng đặt mua</th>
						<th colspan="2">Thành tiền</th>
					</tr>
				</thead>
				<tbody>
					<?php 
					$index = 0;
					foreach($_SESSION['order_cart'] as $key => $value) {
					$post = get_post($value->goods_id);
					// $images = jamnews_get_images_album();
					if (isset($value)) {
						$unit_price = get_post_meta($post->ID,"cost-deal",true);
						$total_price = $value->qty * $unit_price;
					
					?>
					
					<tr>
						<td>
						<input type="hidden" name="cart_index" value="<?php echo $index; 	$index++;?>"></input>
						<input type="hidden" name="unit_price" value="<?php echo $unit_price;?>"></input>
						<a href="<?php echo get_permalink();?>">
						<?php the_post_thumbnail("thumbnail");?>
						</a>
						</td>
						<td><?php echo get_the_title();?></td>
						<td class="unit_price"><?php echo get_price($post);?></td>
						<td>
					
							  <div class="col-lg-4">
								<div class="input-group">
									<span class="input-group-btn">
										<a class="btn btn-default" type="button" id="btnAddCart" onclick="return update_order_qty_cart(this,'sub')" href="<?php echo admin_url("admin-ajax.php?action=update-order-cart-qty");?>" ref="sub">-</a>
									</span>
									<input type="text" class="form-control" style="padding: 1px; text-align: center;" 
                                    value="<?php echo $value->qty;?>" id="txtQty"> </input>
									<span class="input-group-btn">
										<a class="btn btn-default" id="btnRemoveCart" onclick="return update_order_qty_cart(this,'add')" href="<?php echo admin_url("admin-ajax.php?action=update-order-cart-qty");?>" ref="add">+</a>
									</span>
								</div><!-- /input-group -->
							  
							  </div>
						</td>
						<td >
							<span class="strong" id="txtTotalPrice" value=""> <?php echo $total_price. " $$$"; ?></span>
						</td>
					</tr>
					
					<?php } } ?>
				</tbody>
			</table>
    		
    		</div><!-- #content -->            
            <?php woo_main_after();?>
    	</div><!-- #primary -->
        
    </div>
	



<?php get_footer(); ?>

